<html>
<head>
 <!--
    CPAINT (Cross-Platform Asynchronous INterface Toolkit) - Version 2

    http://sf.net/projects/cpaint
    
    released under the terms of the GPL
    see http://www.fsf.org/licensing/licenses/gpl.txt for details

    authors:  Paul Sullivan <wiley14@gmail.com>, Dominique Stender <dstender@st-webdevelopment.de>
    Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint
  //-->
	<title>cpaint2 variable passing</title>
	<script type="text/javascript" src="../../cpaint2.inc.compressed.js"></script>
	<script type="text/javascript">
	<!--
		var cp = new cpaint();
		cp.set_transfer_mode('get');
		cp.set_response_type('text');
		cp.set_debug(2);
	
		function objpass() {
      var selectbox = document.getElementById('activeTest');

      cp.call('objpass.php', 'print_var', response, testvar[selectbox.options[selectbox.selectedIndex].value]);
			document.getElementById('request').innerHTML = JSON.stringify(testvar[selectbox.options[selectbox.selectedIndex].value]);
      return false;
		}

		function response(result) {
			document.getElementById('response').innerHTML = '<pre>' + result + '</pre>';
		}
	//-->
	</script>
</head>
<body>
	This script tests the ability of CPAINT to pass arrays and objects to the backend.<br />
  If you'd like to influence the parameters in use, edit the
  source of this example<br />
  <br />
  <strong>Note</strong> that JSON in itself does not support hashlists / collections / associative arrays. What CPAINT does to dodge this limitation is to convert associative arrays into objects.
	<br />
	<form action="#" onSubmit="return objpass()">
      <p>
        <select id="activeTest">
          <option value="1" selected>passing a string</option>
          <option value="2">passing a number</option>
          <option value="3">passing a (nested) array</option>
          <option value="4">passing an associative array</option>
          <option value="5">passing an object</option>
        </select>
      </p>
      
      <p>          <input type="submit" value="start test" />
      </p>
	</form>
  <div id="request"></div>
	<div id="response"></div>
  <script type="text/javascript">
  <!--
    // now the test variables
    var testvar = new Array();
    testvar[1] = 'just a string';

    testvar[2] = 3.141;

    testvar[3] = new Array();
    testvar[3][0]     = 'first array value';
    testvar[3][1]     = '2nd val';
//    testvar[3][2]     = 42;
    testvar[3][3]     = new Array();
    testvar[3][3][0]  = 'nested key';
    testvar[3][3][1]  = 3.141;
    testvar[3][3][2]  = false;
    testvar[3][3][3]  = true;

    testvar[4]  = new Array();
    testvar[4]['first']   = 'first hash key';
    testvar[4]['second']  = 3.141;
    testvar[4]['third']   = 42;
    testvar[4]['nested']  = new Array();
    testvar[4]['nested']['tick']  = 'tack';
    testvar[4]['nested']['foo']   = 'bar';
    
    testvar[5] = cp;
  //-->
  </script>
</body>
</html>
